package com.ruoyi.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.EQuestion;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.IEQuestionService;
import com.ruoyi.system.service.ISysUserService;

/**
 * 设备问题报备Controller
 * 
 * @author ruoyi
 * @date 2020-07-02
 */
@Controller
@RequestMapping("/system/question")
public class EQuestionController extends BaseController {
	private String prefix = "system/question";

	@Autowired
	private IEQuestionService eQuestionService;
	@Autowired
	private ISysUserService iSysUserService;

	@RequiresPermissions("system:question:view")
	@GetMapping()
	public String question( ModelMap mmap) {
		List<SysUser> users = iSysUserService.getAllUser();
		mmap.put("users", users);
		return prefix + "/question";
	}

	/**
	 * 查询设备问题报备列表
	 */
	@RequiresPermissions("system:question:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(EQuestion eQuestion) {
		startPage();
		List<EQuestion> list = eQuestionService.selectEQuestionList(eQuestion);
		return getDataTable(list);
	}

	/**
	 * 导出设备问题报备列表
	 */
	@RequiresPermissions("system:question:export")
	@Log(title = "设备问题报备", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(EQuestion eQuestion) {
		List<EQuestion> list = eQuestionService.selectEQuestionList(eQuestion);
		ExcelUtil<EQuestion> util = new ExcelUtil<EQuestion>(EQuestion.class);
		return util.exportExcel(list, "question");
	}

	/**
	 * 新增设备问题报备
	 */
	@GetMapping("/add")
	public String add( ModelMap mmap) {
		List<SysUser> users = iSysUserService.getAllUser();
		mmap.put("users", users);
		return prefix + "/add";
	}

	/**
	 * 新增保存设备问题报备
	 */
	@RequiresPermissions("system:question:add")
	@Log(title = "设备问题报备", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(EQuestion eQuestion) {
		eQuestion.setCreateBy(ShiroUtils.getSysUser().getUserName());
		return toAjax(eQuestionService.insertEQuestion(eQuestion));
	}

	/**
	 * 修改设备问题报备
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {

		List<SysUser> users = iSysUserService.getAllUser();
		mmap.put("users", users);

		EQuestion eQuestion = eQuestionService.selectEQuestionById(id);
		mmap.put("eQuestion", eQuestion);
		return prefix + "/edit";
	}
	@GetMapping("/editN/{id}")
	public String editN(@PathVariable("id") Long id, ModelMap mmap) {
		
		List<SysUser> users = iSysUserService.getAllUser();
		mmap.put("users", users);
		
		EQuestion eQuestion = eQuestionService.selectEQuestionById(id);
		mmap.put("eQuestion", eQuestion);
		return prefix + "/editN";
	}

	/**
	 * 修改保存设备问题报备
	 */
	@RequiresPermissions("system:question:edit")
	@Log(title = "设备问题报备", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(EQuestion eQuestion) {
		eQuestion.setUpdateBy(ShiroUtils.getSysUser().getUserName());
		return toAjax(eQuestionService.updateEQuestion(eQuestion));
	}

	/**
	 * 删除设备问题报备
	 */
	@RequiresPermissions("system:question:remove")
	@Log(title = "设备问题报备", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(eQuestionService.deleteEQuestionByIds(ids));
	}
}
